package com.quzhi.sys.service.impl;

import com.quzhi.sys.entity.Blacklist;
import com.quzhi.sys.entity.Order;
import com.quzhi.sys.entity.User;
import com.quzhi.sys.mapper.BlacklistMapper;
import com.quzhi.sys.service.IBlacklistService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Xibing
 * @since 2024-08-12
 */
@Service
public class BlacklistServiceImpl extends ServiceImpl<BlacklistMapper, Blacklist> implements IBlacklistService {

    @Autowired
    private UserServiceImpl userService;

    @Autowired
    private OrderLogServiceImpl orderLogService;

    /**
     * 匹配黑名单用户
     */
    @Override
    public void selectBlackListUser(Order order, String token) {
        User userinfoForBack = userService.getUserinfoForBack(token);

        List<Blacklist> blacklists = this.baseMapper.selectList(null);

        if(order.getUserName() != null){
            for (Blacklist blacklist : blacklists) {
                if(order.getUserName().equals(blacklist.getUsername())){
                    // 用户名单匹配到黑名单，添加到订单日志
                    orderLogService.AddUserLog(order.getId(), "用户名匹配到黑名单", userinfoForBack.getUsername());
                }
            }
        }

        if(order.getPhone() != null){
            for (Blacklist blacklist : blacklists) {
                if(order.getPhone().equals(blacklist.getPhone())){
                    // 用户名单匹配到黑名单，添加到订单日志
                    orderLogService.AddUserLog(order.getId(), "用户手机号匹配到黑名单", userinfoForBack.getUsername());
                }
            }
        }

    }
}
